package net.comm.blog.db;


import java.sql.ResultSet;
import java.sql.SQLException;


import net.comm.blog.bean.BaseBlog;
import net.comm.param.bean.BaseProperty;
import net.comm.util.StringUtil;

import org.apache.log4j.Logger;
import org.sakaiproject.db.api.SqlReader;

public class DbBlogService implements SqlReader
{

	static Logger logger = Logger.getLogger(DbBlogService.class.getName());

	/**
	 * Read from the result one set of fields to create a Resource.
	 * 
	 * @param result
	 *        The Sql query result.
	 * @return The Resource object.
	 */
	public Object readSqlResultRecord(ResultSet result)
	{
		try
		{		
			
			int blogID = result.getInt(1);			//博客ID
			int follID = result.getInt(2);			//	评论ID
			int upFollID = result.getInt(3);		//	评论ID
			String title = StringUtil.getValue(result.getString(4));	//	博客标题
			String intro = StringUtil.getValue(result.getString(5));	//	内容简介
			String content = StringUtil.getValue(result.getString(6));	//	内容
			String tags = StringUtil.getValue(result.getString(7));	//	关键词
			int f_ID = result.getInt(8);		//	附件ID
			String pubTime = StringUtil.getValue(result.getString(9));	//	发布时间
			int userID = result.getInt(10);		//	用户ID
			int upUserID = result.getInt(11);		//	用户ID
			int attachNum = result.getInt(12);	//	浏览次数
			int replyNum = result.getInt(13);	//	评论次数
			int firsort = result.getInt(14);	//	分类一
			int secsort = result.getInt(15);	//	分类二
			int thisort = result.getInt(16);	//	分类三
			String replyFlg = StringUtil.getValue(result.getString(17));	//	是否允许评论
			String blogSet = StringUtil.getValue(result.getString(18));	//	状态
			String status = StringUtil.getValue(result.getString(19));	//	状态
			String mtime = StringUtil.getValue(result.getString(20));	//	最后修改日期			

			// create the Resource from these fields
			return new BaseBlog( blogID,  follID, upFollID, title, intro,  content,  tags,  f_ID,
					 pubTime,  userID, upUserID, attachNum, replyNum,  firsort,  secsort,  thisort,
					 replyFlg, blogSet,  status,  mtime );
		}
		catch (SQLException e)
		{
			logger.error("读取表数据持久层失败！");
			return null;
		}
		
	}
}
